package com.ima.web.dao.impl;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Example;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.ima.web.beans.db.Profile;
import com.ima.web.beans.db.Users;
import com.ima.web.dao.ProfileDao;


@Repository
public class ProfileDaoImpl implements ProfileDao{
	private SessionFactory sessionFactory;
	
	@Autowired
	public void setDependencies(SessionFactory sessionFactory){
		this.sessionFactory = sessionFactory;
	}

	@Override
	public void save(Profile data) {
		Session s = sessionFactory.getCurrentSession();
		s.save(data);
	}

	@Override
	public void delete(Profile data) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public List<Profile> list(Profile data) {
		Session s = sessionFactory.getCurrentSession();
		
		Criteria c = s.createCriteria(Profile.class);
		c.add(Example.create(data));
				
		List<Profile> p = c.list();
		//s.update(u);		
		
		return p;
	}

	@Override
	public Profile findById(int id) {
		Session s = sessionFactory.getCurrentSession();
		
		Profile p = (Profile)s.load(Profile.class, id); 

		return p;
	}
	
}
